<template>
  <div class="tab-control">
    <div class="tab-item" v-for="(item, index) in tabControlData" :key="item.title" @click="btnClick(index)">
      <span :class="{ spanActive: currentIndex === index }">{{ item.title }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TabControl',
  props: ['tabControlData'],
  data() {
    return {
      currentIndex: 0
    }
  },
  methods: {
    btnClick(index) {
      this.currentIndex = index
      this.$router.push(this.tabControlData[index].path)
      this.$emit('tabControlClick', index)
    }
  },
  created() {
    let i = this.tabControlData.findIndex(item => item.path === this.$route.path)
    this.currentIndex = i
  }
}
</script>

<style lang="scss" scoped>
.tab-control {
  height: 0.49rem;
  display: flex;
  border-bottom: 0.5px solid #eee;
  background: white;
  .tab-item {
    height: 100%;
    flex: 1;
    text-align: center;
    line-height: 0.49rem;
    font-size: 0.12rem;
    .spanActive {
      border-bottom: 0.025rem solid #ff5f16;
      padding-bottom: 0.15rem;
      color: #ff5f16;
    }
  }
}
</style>